package cn.retalsystem.util;

import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: 官宝星
 * @Date: 2019/11/6 22:29
 * @Version 1.0
 * @描述：
 */
public class StringToDateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String s) {

        try {
            if(s.isEmpty()||s==null){
                throw new RuntimeException("请输入要转换的");
            }
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            Date date = format.parse(s);
            return date;
        } catch (Exception e) {
            throw new RuntimeException("输入的日期有误");
        }
    }
}
